#e
#Title[Eufbh[|CYXg[v]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_ChenRan.txt"
	let imageBoss = GetCurrentScriptDirectory() ~ "img\dot_ran.png";

	let name	= "Eufbh[|CYXg[v";
    	let csd        = GetCurrentScriptDirectory;
    	let shotImage   = csd ~ "data_usershot.txt";
	let wavA	= csd ~ "SE\shot1.wav";
	let dokushot	= 124;
	let r		= 0;
	let r2		= 75;
	let om		= 3;
	let t		= 0;
	let t2		= 0;
	let arg		= 0;
	let angle	= 0;
	let graphic	= dokushot;

	let wIni = 120;
	
	///////////////////////////////////////////////////////////

	@Initialize{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
	LoadGraphic(imageBoss);
	InitializeAction();
	    
        SetMovePosition02(GetCenterX(), GetClipMinY+120, wIni);
        SetLife(3000);
        SetTimer(61);
	SetScore(1000000);
        SetDamageRate(100, 20);
	SetInvincibility( 260 );
        LoadUserShotData(shotImage);

	TMain();
	TMain2();
	TSub();

	}
		
	@MainLoop{
	    SetCollisionA(GetX, GetY, 32);
	    SetCollisionB(GetX, GetY, 16);



	    yield;
	}
	
	@DrawLoop{
	    DrawBoss(imageBoss);
	    SetTexture(imageBoss);
	    DrawGraphic(GetX(), GetY());
	}
		
	@Finalize{
	    DeleteGraphic(imageBoss);
	}

	task TMain{

	    yield;
	    loop(wIni){ yield; }

	loop{
	    loop(75){
	    PlaySE(wavA);
	    doku;
	    r--;
	    loop(5){ yield; }
	    }
	    loop(150){
	    PlaySE(wavA);
	    doku;
	    r++;
	    loop(5){ yield; }
	    }
	    loop(75){
	    PlaySE(wavA);
	    doku;
	    r--;
	    loop(5){ yield; }
	    }
	}
	}

	task TMain2{

	    yield;
	    loop(wIni){ yield; }

	loop{
	    loop(75){
	    doku2;
	    r2++;
	    loop(5){ yield; }
	    }
	    loop(150){
	    doku2;
	    r2--;
	    loop(5){ yield; }
	    }
	    loop(75){
	    doku2;
	    r2++;
	    loop(5){ yield; }
	    }
	}
	}

	task TSub{

	    yield;
	    loop(wIni){ yield; }

	    loop{
	    move;
	    loop(50){ yield; }
	    }
	}

	sub doku{

	ascent(let i in 0 .. 2){
	ascent(let i in 0 .. 2){
	let obj		= Obj_Create(OBJ_SHOT);

        Obj_SetSpeed(obj, 3);
        Obj_SetPosition(obj, GetX + r*cos(om*t + arg),
                             GetY + r*sin(om*t + arg));
        Obj_SetAngle(obj, arg+angle+t);
        ObjShot_SetDelay(obj, 20);
        ObjShot_SetGraphic(obj, graphic);

	arg   +=	180;
	t++;
	}
	angle +=	180;
	}
	}

	sub doku2{

	ascent(let i in 0 .. 2){
	ascent(let i in 0 .. 2){
	let obj		= Obj_Create(OBJ_SHOT);

        Obj_SetSpeed(obj, 3);
        Obj_SetPosition(obj, GetX + r2*cos(om*t2 + arg),
                             GetY + r2*sin(om*t2 + arg));
        Obj_SetAngle(obj, arg+angle+t2);
        ObjShot_SetDelay(obj, 20);
        ObjShot_SetGraphic(obj, graphic);

	arg   +=	180;
	t2--;
	}
	angle +=	180;
	}
	}

    // ړ
    sub move {
        let wMove = 40;

        moveToPlayer(rand(40, 80), rand(-40, 40), wMove,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	SetAction(ACT_MOVE,wMove);
	wait(wMove);
	SetAction(ACT_STAND,wMove);
	wait(wMove);
    }

    // ȂׂvC[̕Ɉړ
    //   xMove  : x ̈ړʁi̐j
    //   yAdd   : y ̈ړ
    //   frame  : ړɗvt[
    //   left   : ȉA͈
    //   top    :
    //   right  :
    //   bottom :
    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX) {
            // vC[EɓG΁AG͍ɓ܂B
            x = GetX - xMove;

            // AAG̈̍[ɂ悤ȂAEɓ܂B
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            // Ȃ΁AG͉Eɓ܂B
            x = GetX + xMove;

            // AAG̈̉E[Eɂ悤ȂAɓ܂B
            if(right < x) {
                x = GetX - xMove;
            }
        }

        // ̈̊Oɍsꍇ́A[Ŏ~߂܂B
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }

    // w t[҂
    function wait(w) {
        loop(w) { yield; }
    }
}